package main;

import main.Game.Board;
import main.Game.BoardGroup;
import main.Game.Color;

public class BaseGame {

	protected Controler_board boardct;
	protected Controler_player playerct;
	protected Controler_game gamect;

	public BaseGame(int userNum) {
		boardct = new Controler_board();
		playerct = new Controler_player(userNum);
	}

	protected boolean _Game_end() {
		return playerct.end();
	}

	protected int _winnerNum() {
		return playerct.winnerNum();
	}

	protected int _next_Player() {
		return playerct.next();
	}

	protected int _turn() {
		return playerct.Turn();
	}

	protected BoardGroup _player_board(int id, boolean is_own)
			throws CloneNotSupportedException {
		return playerct.player[id].board(is_own);
	}

	protected void addBoard(int id, Board b) throws CloneNotSupportedException {
		_player_board(id, true).add(b);
	}

	protected boolean _guessBoard(int id, int num, int value) {
		return playerct.player[id].board.guessBoard(num, value);
	}

	protected void player_give_up(int id) {
		playerct.player[id].lose = true;
		playerct.player[id].board.showall();
	}

	protected void reset() {
		playerct.reset();
		boardct.resetBoard();
	}

	/**
	 * 依据int转换成color
	 * 
	 * @param a
	 * @return
	 */
	protected Color _trans(int a) {
		if (a == 1)
			return Color.white;
		else
			return Color.black;
	}

	protected Color _rand_Color() {
		int a = (int) (Math.random() * 2);
		if (a == 1)
			return Color.white;
		else
			return Color.black;
	}

	protected void _allocate_Board(int id) {
		Board temp = boardct.NewBoard(_rand_Color());
		playerct.player[id].add(temp);
		// System.out.printf("Allocate player %d board: %d\n", id, temp.num);
	}

	protected void _allocate_Board_first() {
		for (int i = 0; i < playerct.num; i++) {
			for (int j = 0; j < boardct.init_board_num; j++) _allocate_Board(i);
		}
	}
}
